package com.qkl.xiatang.app.entity.user;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.qkl.xiatang.app.dto.user.CompanyDTO;
import com.qkl.xiatang.app.entity.BaseEntity;
import com.qkl.xiatang.app.utils.appenum.AppUserStatus;
import lombok.Data;
import net.sf.jsqlparser.util.validation.metadata.DatabaseException;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;

import java.util.Date;
import java.util.List;
import java.util.Map;

@Data
@TableName(value = "app_user")
public class AppUserInfo extends BaseEntity {

    @TableId(type= IdType.ASSIGN_ID)
    private String id;

    private String username;

    private String name;

    private String avatar;

    private String phone;

    private String password;

    private String salt;

    private Integer status;

    private Integer delFlag;

    private String identity;

    private String companyId;

    private String companys;

    private String companyApply;

    private String token;

    private String deviceId;

    private String additInfo;

    @TableField(exist = false)
    private List<AppUserIdentityEntity> appUserIdentityEntities;

    @TableField(exist = false)
    private List<CompanyDTO> companyList;

    public CompanyDTO companyInfo(){
        if(ObjectUtils.isNotEmpty(companyList)){
            for(CompanyDTO companyDTO : companyList){
                if(StringUtils.isNotEmpty(companyId) && companyId.equals(companyDTO.getId())){
                    return companyDTO;
                }
            }
        }
        return null;
    }

    public boolean delete(){
        return Integer.valueOf(1).equals(delFlag);
    }

    public boolean statusCancel(){
        return AppUserStatus.isCancel(status);
    }

}
